/**
 * 
 */
package org.gigi;

import java.lang.reflect.Field;

/**
 * 工具类
 *
 * @author Eugene Wang 2011-5-28
 * @see
 */
public class BeanUtils {
	/**
	 * 设置对象的私有属性的值
	 * @param source
	 * @param fieldName
	 * @param fildValue
	 */
	public static void setFieldValue(Object source, String fieldName, Object fildValue) {
		Field field = null;
		try {
			field = source.getClass().getDeclaredField(fieldName);
		} catch (NoSuchFieldException e) {
			return;
		}
		field.setAccessible(true);
		try {
			field.set(source, fildValue);
		} catch (IllegalAccessException e) {
			return;
		}
	}
	/**
	 * 获取对象的私有属性的值
	 * @param source
	 * @param fieldName
	 * @return
	 */
	public static Object getFieldValue(Object source, String fieldName) {
		Field field = null;
		try {
			field = source.getClass().getDeclaredField(fieldName);
		} catch (NoSuchFieldException e) {
			return null;
		}
		field.setAccessible(true);
		try {
			return field.get(source);
		} catch (IllegalAccessException e) {
			return null;
		}
	}
}
